define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'chase/design_service/index' + location.search,
                    add_url: 'chase/design_service/add',
                    edit_url: 'chase/design_service/edit',
                    del_url: 'chase/design_service/del',
                    multi_url: 'chase/design_service/multi',
                    table: 'design_services',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'design_id', title: __('Design_id')},
                        {field: 'design.nickname', title: __('设计师名称')},
                        {field: 'service_id', title: __('Service_id')},
                        {field: 'service.service_name', title: __('服务名称')},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        // {field: 'online', title: __('Online'), searchList: {"no":__('Online no'),"yes":__('Online yes')}, formatter: Table.api.formatter.toggle, yes: 'yes', no: 'no'},
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function () {
                                return `<a href="javascript:;" class="btn btn-xs btn-primary btn-dragsort" data-toggle="tooltip" title="" data-table-id="table" data-field-index="10" data-row-index="0" data-button-index="0" data-original-title="拖动进行排序"><i class="fa fa-arrows"></i></a>
                                        <a href="/shijiu.php/chase/design/edit/ids/10" class="btn btn-xs btn-success btn-editone" data-toggle="tooltip" title="" data-table-id="table" data-field-index="10" data-row-index="0" data-button-index="1" data-original-title="编辑"><i class="fa fa-pencil"></i></a>
                                        `;
                            }}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        design: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'chase/design_service/design' + location.search,
                    add_url: 'chase/design_service/add',
                    edit_url: 'chase/design_service/edit',
                    del_url: 'chase/design_service/del',
                    multi_url: 'chase/design_service/multi',
                    table: 'design_services',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                showExport: false,
                commonSearch: false,
                search: false,
                showToggle: false,
                showColumns: false,
                pagination: false,
                columns: [
                    [
                        // {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'design_id', title: __('Design_id')},
                        {field: 'service_id', title: __('Service_id')},
                        {field: 'service.service_name', title: __('服务名称')},
                        {field: 'price', title: __('Price'), operate:'BETWEEN'},
                        {field: 'line_price', title: __('划线价格'), operate:'BETWEEN'},
                        // {field: 'weigh', title: __('Weigh')},
                        // {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        // {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: function () {
                                return ` <a href="javascript:;" class="btn btn-xs btn-primary btn-dragsort" title="拖动进行排序"><i class="fa fa-arrows"></i></a> ` +
                                        ` <a href="javascript:;" class="btn btn-xs btn-success btn-editone" title="编辑" >编辑</a> ` +
                                        ` <a href="javascript:;" class="btn btn-xs btn-danger btn-delone" title="删除" >取消关联</a> `;
                            }}
                    ]
                ]
            });

            $('#toolbar').on('click', '.btn-create', function () {
                var design_id = $(this).data('id');
                Fast.api.open('/shijiu.php/chase/design_service/create?design_id='+design_id, '关联服务')
            })

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        create: function () {
            Controller.api.bindevent();
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});